<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<table class="layui-hide" id="test" lay-filter="test"></table>



<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">查看详情</a>
</script>


<script src="/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script th:inline="javascript">
    layui.use(['table','jquery'], function(){
        var table = layui.table
            ,$ =layui.jquery;

        table.render({
            elem: '#test'
            ,url:'/approve/getData?node='+[[${param.node}]]
            ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            ,title: '出差审批表'
            ,cols: [
                [

                    {field:'travelApplication.numbering', title:'编号',  fixed: 'left', unresize: true, sort: true, templet:'<div>{{d.travelApplication.numbering}}</div>'}
                    ,{field:'applicationName', title:'申请人', edit: 'text',templet:'<div>{{d.travelApplication.staff.name}}</div>'}
                    ,{field:'', title:'出差时间',  edit: 'text', templet:'<div>{{ layui.util.toDateString(d.travelApplication.planTravelDate, "yyyy-MM-dd") }}</div>' }
                    ,{field:'applicationTime', title:'申请时间',  edit: 'text', sort: true,templet:'<div>{{ layui.util.toDateString(d.travelApplication.addTime, "yyyy-MM-dd") }}</div>'}
                    ,{field:'traveNumber', title:'出差人数', templet:'<div>{{d.travelApplication.travelNumber}}</div>'}
                    ,{field:'travelApplication.supplier.name', title:'走访单位',width:150,templet:'<div>{{d.travelApplication.supplier.name}}</div>'}
                    ,{field:'planMoney', title:'预算', sort: true,templet:'<div>{{d.travelApplication.planMoney}}</div>'}
                    ,{field:'states', title:'当前状态', templet:'<div>{{d.states}}</div>'}
                    ,{fixed: 'right', title:'操作', toolbar: '#barDemo'}
                ]
            ]
            ,page: true
        });

        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选');
                    break;

                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            if(obj.event === 'edit'){
                //layer.alert('编辑行：<br>'+ JSON.stringify(data))
                parent.layer.open({
                    title:'出差申请',
                    type:2,
                    content:'/business-trip/applicationDetails?id='+data.travelApplication.id,
                    area: ['1200px', '600px'],
                    btn:['驳回','通过'],
                    end:function(){window.location.reload()},
                    yes:function(index, layero){
                        if(data.state==0||data.state==2){
                            parent.layer.closeAll();
                            parent.layer.msg("您已审批过");
                        }
                        else{
                            parent.layer.prompt({
                                formType: 2,
                                value: '',
                                title: '请输入驳回原因',
                                btn:['确定','返回'],
                                area: ['600px', '250px'],
                                zIndex: layer.zIndex,
                                yes:function(index, layero) {
                                    var value = layero.find(".layui-layer-input").val();
                                    if (value == ""){
                                        parent.layer.msg("请输入驳回原因")
                                    } else {
                                        $.ajax({
                                            url:'/approve/saveTheApprovalForm',
                                            data:{"id":data.travelApplication.id,"node":data.travelApplication.processNode.node,"value":value,"state":0},
                                        })
                                        parent.layer.closeAll();

                                        parent.layer.msg("驳回申请");

                                    }

                                }
                            }, );
                        }

                    },
                    btn2:function(index, layero){
                        if(data.state==0||data.state==2){
                            parent.layer.closeAll();
                            parent.layer.msg("您已审批过");
                        }
                        else{
                            $.ajax({
                                url:'/approve/approvalForm',
                                data:{"id":data.travelApplication.id,"node":data.travelApplication.processNode.node,},
                            })


                            layer.msg("通过申请");
                        }


                    },
                    shade: [0.3, '#393D49'],
                    shadeClose:false,
                    moveOut:true,
                })
            }else if(obj.event === 'log'){
                window.location.href="/approve/travelLog?id="+data.id;

            }
        });

    });

</script>
</body>
</html>